<!--{template common/header_simple_start}-->
<link rel="stylesheet" type="text/css" href="static/tagsinput/jquery.tagsinput.css?{VERHASH}">
<script type="text/javascript" src="static/tagsinput/jquery.tagsinput.js?{VERHASH}"></script>
<script type="text/javascript" src="dzz/system/scripts/selorg.js?{VERHASH}"></script>
<script type="text/javascript">
	<!--{if $openarr}-->
	selorg.openarr = $openarr;
	<!--{/if}-->
</script>
<style>
	.img_128_128 {
		max-width: 128px;
		max-height: 128px;
		border: 1px solid #CCC;
		padding: 2px;
	}
	.btn-sorg {
		margin: 5px;
	}
	
	* html .img_128_128 {
		width: expression(this.width > 128 && this.width>=this.height ? 128: true);
		height: expression(this.height > 128 && this.width<=this.height ? 128: true);
	}
</style>
<!--{template common/header_simple_end}-->
<!--{template common/commer_header}-->
<div class="bs-container clearfix">
	<div class="bs-left-container  clearfix">
		<!--{template left}-->
	</div>
	<div class="left-drager">
		<div class="left-drager-op">
			<div class="left-drager-sub"></div>
		</div>
	</div>	
	<div class="bs-main-container">	
		<div class="main-header clearfix">
			<!--{if !$appid}-->
				<h4 class="main-header-title navbar-left">{lang add_app}</h4>			
			<!--{else}-->
				<h4 class="main-header-title navbar-left">{lang edit_app}</h4>
			<!--{/if}-->
			
			<!--{if !$appid && $op=='edit'}-->
			<div  class="button_add_content">
				<a href="{MOD_URL}&op=edit&do=add&refer=$refer" id="button_add1" title="{lang add_app}" class="hide">+</a>				
				<a href="{MOD_URL}&op=cp&do=import&refer=$refer" id="button_add2" class="hide" title="{lang import_type_app}" style="font-size:20px ;"><span  class="glyphicon glyphicon-download-alt"></span></a>				
				<a href="javascript:;" id="button_add" style="z-index: 10;">+</a>				
			</div>
			<!--{/if}-->
		</div>
		<div class="main-content">
      <form id="appform" name="appform" class="form-horizontal-left form-horizontal" action="{MOD_URL}&op=edit&appid=$appid" method="post" enctype="multipart/form-data" onsubmit="return validate(this)">
        <input type="hidden" name="appsubmit" value="true" />
        <input type="hidden" name="appid" value="$appid" />
        <input type="hidden" name="refer" value="$refer" />
        <input type="hidden" name="formhash" value="{FORMHASH}" />
        <div class="row mb-3">
          <label for="appname" class="col-sm-2">{lang application_name}</label>
          <div class="col-sm-10">
            <input type="text" class="form-control" id="appname" name="appname" autocomplete="off" value="$app[appname]">
          </div>
          <span class="help-block"></span> 
        </div>
        <div class="row mb-3">
          <label for="identifier" class="col-sm-2">{lang application_identifier}</label>
          <div class="col-sm-10">
            <input type="text" class="form-control" id="identifier" name="identifier" autocomplete="off" value="$app[identifier]">
            <ul class="help-block">
              {lang app_application_identifier_text}
            </ul>
          </div>
        </div>
        <div class="row mb-3">
          <label for="app_path" class="col-sm-2">{lang application_app_path}</label>
          <div class="col-sm-10">
            <input type="text" class="form-control" id="app_path" name="app_path" autocomplete="off" value="$app[app_path]">
            <ul class="help-block">
              {lang app_application_app_path_text}
            </ul>
          </div>
        </div>
        <div class="row mb-3">
          <label for="appurl" class="col-sm-2">{lang application_site}</label>
          <div class="col-sm-10">
            <input type="text" class="form-control" id="appurl" name="appurl" autocomplete="off" value="$app[appurl]">
            <ul class="help-block">
              {lang app_application_site_text}
            </ul>
          </div>
        </div>
        <div class="row mb-3">
          <label for="appadminurl" class="col-sm-2">{lang application_appadminurl}</label>
          <div class="col-sm-10">
            <input type="text" class="form-control" id="appadminurl" name="appadminurl" autocomplete="off" value="$app[appadminurl]">
            <ul class="help-block">
              {lang app_application_appadminurl_text}
            </ul>
          </div>
        </div>
        <div class="row mb-3">
          <label for="vendor" class="col-sm-2">{lang supplier}</label>
          <div class="col-sm-10">
            <input type="text" class="form-control" id="vendor" name="vendor" autocomplete="off" value="$app[vendor]">
            <span class="help-block">{lang application_provider_name}</span>
          </div>
        </div>
        <div class="row mb-3">
          <label class="col-sm-2">{lang application_ico}</label>
          <div class="col-sm-10">
            <!--{if $appid>0}-->
              <input id="fileiz_0" class="form-control" name="TMPiconnew" value="" style="display: none;" type="file">
              <input id="fileiz_1" class="form-control" style="" name="iconnew" value="$app[appico]" type="text">
              <a id="fileiz_0a" style="" href="javascript:;" onclick="document.getElementById('fileiz_1a').style.fontWeight = '';this.style.fontWeight = 'bold';document.getElementById('fileiz_1').name = 'TMPiconnew';document.getElementById('fileiz_0').name = 'iconnew';document.getElementById('fileiz_0').style.display = '';document.getElementById('fileiz_1').style.display = 'none'">{lang uploading}</a>&nbsp;
              <a id="fileiz_1a" style="font-weight: bold;" href="javascript:;" onclick="document.getElementById('fileiz_0a').style.fontWeight = '';this.style.fontWeight = 'bold';document.getElementById('fileiz_0').name = 'TMPiconnew';document.getElementById('fileiz_1').name = 'iconnew';document.getElementById('fileiz_1').style.display = '';document.getElementById('fileiz_0').style.display = 'none'">{lang type_link}</a>
            <!--{else}-->
              <input id="fileiz_0" class="form-control" name="iconnew" value="" type="file">
              <input id="fileiz_1" class="form-control" style="display: none;" name="TMPiconnew" value="$app[appico]" type="text">
            <p>
              <a id="fileiz_0a" style="font-weight: bold;" href="javascript:;" onclick="document.getElementById('fileiz_1a').style.fontWeight = '';this.style.fontWeight = 'bold';document.getElementById('fileiz_1').name = 'TMPiconnew';document.getElementById('fileiz_0').name = 'iconnew';document.getElementById('fileiz_0').style.display = '';document.getElementById('fileiz_1').style.display = 'none'">{lang uploading}</a>&nbsp;
              <a id="fileiz_1a" style="" href="javascript:;" onclick="document.getElementById('fileiz_0a').style.fontWeight = '';this.style.fontWeight = 'bold';document.getElementById('fileiz_0').name = 'TMPiconnew';document.getElementById('fileiz_1').name = 'iconnew';document.getElementById('fileiz_1').style.display = '';document.getElementById('fileiz_0').style.display = 'none'">{lang type_link}</a>
            </p>
            <!--{/if}-->
            <span class="help-block">{lang suggest_image_size}128X128 px</span>
          <span class="help-block">
            <!--{if $appid}--><img class="img_128_128" src="$app[appico]?t=$_G[timestamp]" >
            <!--{else}--> <img class="img_128_128" src="dzz/images/default/icodefault.png" >
            <!--{/if}-->
            </span>
          </div>
        </div>
        <div class="row mb-3">
          <label class="col-sm-2">{lang group_permissions}</label>
          <div class="col-sm-10">
            <!--{loop $grouptitle $key $value}-->
            <div class="form-check form-check-inline">
              <input class="form-check-input" type="radio" class="form-check-input" id="group$key" name="group" value="$key" <!--{if $app[group]==$key}-->checked<!--{/if}--> onclick="{if $key==1}jQuery('#perm_depart').show();{else}jQuery('#perm_depart').hide();{/if}">
              <label class="form-check-label" for="group$key">$value</label>
            </div>
            <!--{/loop}-->
            <span class="help-block">{lang app_group_permissions}</span>
          </div>
        </div>
        <div class="row mb-3" id="perm_depart" <!--{if $app[ 'group']!=1}-->style="display:none"<!--{/if}-->>
          <label class="col-sm-2">{lang department_permissions}</label>
          <div class="col-sm-10">
            <div class="dropdown controls_adapt">
              <button class="btn btn-primary dropdown-toggle" type="button" id="orgids_Menu" data-bs-toggle="dropdown" aria-expanded="false">{lang please_select_a_organization_or_department}</button>
              <div id="orgids_dropdown_menu" class="dropdown-menu org-sel-box" role="menu" aria-labelledby="orgids_Menu">
                <iframe name="orgids_iframe" class="org-sel-box-iframe" src="index.php?mod=system&op=orgtree&ctrlid=orgids&multiple=1&nouser=1&stype=1" frameborder="0" marginheight="0" marginwidth="0" width="100%" height="100%" allowtransparency="true"></iframe>
              </div>
            </div>
            <div id="orgids">
              <!--{loop $sel_org $value}-->
              <button id="orgids_sl_$value[orgid]" type="button" class="btn btn-outline-secondary btn-sorg" data-val="$value['orgid']">
                {eval echo avatar_group($value['orgid']);} $value[orgname] 
                <a href="javascript:;" class="ibtn dzz dzz-close"  title="{lang delete}" onclick="selorg.remove('orgids',this);"></a>
              </button>
              <!--{/loop}-->
            </div>

            <input id="sel_orgids" name="orgids" type="hidden" value="$sel" />
            <span class="help-block">{lang app_set_application_jurisdiction}</span>
          </div>
        </div>
        <div class="row mb-3">
          <label class="col-sm-2" for="tag">{lang application_label}</label>
          <div class="col-sm-10">
            <div class="input-group mb-3">
              <input class="js-tags-input form-control" type="text" name="tag" id="tag" autocomplete="off" ata-source="$tag_source" data-items="5" value="$app[tags]">
            </div>
            <ul class="help-block">
              <li>{lang app_number_fields}</li>
              <li>{lang app_clear_label}</li>
            </ul>
          </div>
        </div>
        <div class="row mb-3">
          <label class="col-sm-2" for="fileext">{lang app_support_extension}</label>
          <div class="col-sm-10">
            <div class="input-group mb-3">
              <input class="js-tags-input form-control" type="text" name="fileext" id="fileext" autocomplete="off" data-source="$fileext_source" value="$app[fileext]">
            </div>
            <ul class="help-block">
            {lang app_not_allowed_open_text}
            </ul>
          </div>
        </div>
        <div class="row mb-3">
          <label class="col-sm-2">{lang open_mode}</label>
          <div class="col-sm-10">
            <div class="form-check form-check-inline">
              <input class="form-check-input" type="radio"id="open1" name="open" value="0" <!--{if $app[open]<1}-->checked<!--{/if}--> onclick="jQuery('#feature').show();">
              <label class="form-check-label" for="open1">{lang app_internal_frame}</label>
            </div>
            <div class="form-check form-check-inline">
              <input class="form-check-input" type="radio"id="open2" name="open" value="1" <!--{if $app[open]>0}-->checked<!--{/if}--> onclick="jQuery('#feature').hide();">
              <label class="form-check-label" for="open2">{lang new_Window}</label>
            </div>
            <ul class="help-block">
            {lang app_internal_frame_text}
            </ul>
          </div>
        </div>
        <div class="row mb-3">
          <label class="col-sm-2">{lang app_application_library}</label>
          <div class="col-sm-10">
            <div class="form-check form-check-inline">
              <input class="form-check-input" type="radio"id="hideInMarket1" name="hideInMarket" value="0" <!--{if $app[hideInMarket]<1}-->checked<!--{/if}-->>
              <label class="form-check-label" for="hideInMarket1">{lang show}</label>
            </div>
            <div class="form-check form-check-inline">
              <input class="form-check-input" type="radio"id="hideInMarket2" name="hideInMarket" value="1" <!--{if $app[hideInMarket]>0}-->checked<!--{/if}-->>
              <label class="form-check-label" for="hideInMarket2">{lang hide}</label>
            </div>
            <span class="help-block">{lang app_application_library_text}</span>
          </div>
        </div>
        <div class="row mb-3">
          <label class="col-sm-2">{lang show_ico}</label>
          <div class="col-sm-10">
            <div class="form-check form-check-inline">
              <input class="form-check-input" type="radio"id="isshow1" name="isshow" value="1" <!--{if $app[isshow]>0}-->checked<!--{/if}-->>
              <label class="form-check-label" for="isshow1">{lang show}</label>
            </div>
            <div class="form-check form-check-inline">
              <input class="form-check-input" type="radio"id="isshow2" name="isshow" value="0" <!--{if $app[isshow]<1}-->checked<!--{/if}-->>
              <label class="form-check-label" for="isshow2">{lang hide}</label>
            </div>
            <span class="help-block">{lang app_show_ico_text}</span>
          </div>
        </div>
      <div class="row mb-3">
        <label class="col-sm-2" for="appdesc">{lang application_introduce}</label>
        <div class="col-sm-10">
          <textarea type="textarea" rows="3" class="form-control" name="appdesc" id="appdesc">$app[appdesc]</textarea>
        </div>
      </div>
      <div id="pic_delete"></div>
      <input id="editbutton" name="appbutton" value="{lang submit}" onclick="validate(this);" style="display: none;" type="button" />
      </form>
      <div class="form-horizontal-left form-horizontal">
        <div class="row mb-3">
          <label class="col-sm-2">{lang application_introduce_img}</label>
          <div class="col-sm-10">
            <!--{if $piclist}-->
            <ul id="pic_container" class="thumbnails list-unstyled ml20">
              <!--{loop $piclist $key $value}-->
              <li class="wd120" style="margin:10px;width:90px;" id="pic_{$value[picid]}">
                <div class="thumbnail text-center" style="margin-bottom:10px;">
                  <img data_src="$value[pic]" src="$value[pic]" />
                </div>
                <p class="text-center">
                  <a class="btn btn-primary" href="javascript:;" onclick="delete_pic(this,{$value[picid]})">{lang delete}</a>
                </p>
              </li>
              <!--{/loop}-->
            </ul>

            <!--{/if}-->

            <table class="tb tb2 ">
              <tbody id="attachbodyhidden" style="display:none">
                <tr class="noborder">
                  <td class="tb27">
                    <form method="post" autocomplete="off" id="upload" action="{MOD_URL}&op=$op&do=upload" enctype="multipart/form-data" target="uploadframe">
                      <input type="file" name="attach" class="pf" size="0" />
                      <span id="localfile"></span>
                      <input type="hidden" name="uploadsubmit" id="uploadsubmit" value="true" />
                      <input type="hidden" name="formhash" value="{FORMHASH}" />
                    </form>
                  </td>
                </tr>
              </tbody>
              <tbody id="attachbody"></tbody>
            </table>

            <script src="admin/scripts/uploadpic.js?{VERHASH}" type="text/javascript"></script>
            <iframe id="uploadframe" name="uploadframe" width="0" height="0" marginwidth="0" frameborder="0" src="about:blank"></iframe>
          </div>
        </div>
        <dl>
          <label></label>
          <input class="btn btn-primary" id="submit_editsubmit" name="appsubmit" value="{lang submit}" type="button" onclick="document.getElementById('editbutton').click();">
        </dl>
      </div>
		</div>
	</div>
</div>

<script type="text/javascript">
	function screen_app(tagid,group){	
		var url = '{MOD_URL}';
		if(tagid){
			url += '&tagid='+tagid;
		}
		if(group){
			url += '&group='+group;
		}
		var inputval = jQuery('#screen_keyword').val();
		if(inputval){
			url += '&keyword='+inputval;
		}
		console.log(url);
//		return false;
		window.location.href =url;	 
	}
	jQuery('#button_add').click(function(){
		if(jQuery("#button_add1").hasClass('hide')){
			jQuery("#button_add").html("×");
			jQuery("#button_add1").removeClass("hide");
			jQuery("#button_add2").removeClass("hide");
			jQuery("#button_add1").stop().animate({top:"-124px"},500);
			jQuery("#button_add2").stop().animate({top:"-62px"},500);
		}else{
			jQuery("#button_add").html("＋");
			jQuery("#button_add1").stop().animate({top:"0px"},500);
			jQuery("#button_add2").stop().animate({top:"0px"},500);
			setTimeout(function(){
				jQuery("#button_add1").addClass("hide");
				jQuery("#button_add2").addClass("hide");
			},500)
			
		}
	});

	jQuery('#un_selector_tag,#un_selector_fileext').on('click', function(e) {
		document.getElementById(this.id.replace('un_selector_', '')).focus();
	});

	function addtaginput(key, id) {
		var html = '<span>';
		html += '<button data-bs-dismiss="alert" class="btn-close" type="button"></button>';
		html += '<em title="' + key + '" class="pull-left">' + key + '</em><input type="hidden"  value="' + key + '" name="' + id + '[]">';
		html += '</span>';
		jQuery('#' + id).val('').before(html).focus();
	}

	function validate(obj) {
		//获取用户部门 并添加到form中

		var appname = document.getElementById('appname');
		var appurl = document.getElementById('appurl');
		var identifier = document.getElementById('identifier');
		var app_path = document.getElementById('app_path');
		var notempty = '{lang not_empty}'; 
		if(appname) {
			var slen = strlen(appname.value);
			if(slen < 1 || slen > 80) {
				showmessage('{lang application_name}'+notempty, 'danger', 3000, 1);
				appname.focus();
				return false;
			}
		}
		if(strlen(appurl.value) < 1) {
			showmessage('{lang application_site}'+notempty, 'danger', 3000, 1);
			appurl.focus();
			return false;
		}
		if(strlen(identifier.value) < 1) {
			showmessage('{lang application_identifier}'+notempty, 'danger', 3000, 1);
			appurl.focus();
			return false;
		}
		if(strlen(app_path.value) < 1) {
			showmessage('{lang application_app_path}'+notempty, 'danger', 3000, 1);
			appurl.focus();
			return false;
		}
		uploadSubmit(obj);
		return true;
	}
	jQuery('input[name="fileext"]').click(function(){
      var val = $(this).val();
      if(val == 0){
         jQuery('#fileext').addClass('hide');
      }else{
          jQuery('#fileext').removeClass('hide');
      }
  })
	jQuery('input[name="tag"]').click(function(){
      var val = $(this).val();
      if(val == 0){
         jQuery('#tag').addClass('hide');
      }else{
          jQuery('#tag').removeClass('hide');
      }
  })
</script>
<script src="static/bootstrap/js/bootstrap-typeahead.js?{VERHASH}"></script>
<!--{template common/footer_simple}-->